import { defineStore } from 'pinia'
import { StorageService } from '@/services/common/storage/storage.service'

export const useTokenStore = defineStore('token', {
  state: () => {
    let token = ''

    const storageToken = StorageService.get('token')

    if (storageToken) {
      token = storageToken
    }

    return { token }
  },
  actions: {
    updateToken(value: string) {
      StorageService.set('token', value)
      this.token = value
    }
  }
})
